package com.example.springbootdemo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName: AtomicIntegerAdd
 * @Description: 原子类新增
 * @Author: TXW
 * @Date: 2023-09-11
 */

public class AtomicIntegerAdd {
    private static final String PREFIX = "YZ";
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
    private static final AtomicInteger COUNTER = new AtomicInteger(0);

    public static String generateNumber() {
        Date currentDate = new Date();
        String dateString = DATE_FORMAT.format(currentDate);
        int count = COUNTER.getAndIncrement();
        String countString = String.format("%04d", count);
        return PREFIX + dateString + countString;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(generateNumber());
        }
    }
}
